package com.keshan.service.impl;

import com.keshan.mapper.HeartrateMapper;
import com.keshan.pojo.Heartrate;
import com.keshan.pojo.HeartrateDayAvg;
import com.keshan.pojo.HeartrateExample;
import com.keshan.utils.DateUtil;
import com.keshan.pojo.HeartrateHide;
import com.keshan.service.HeartrateServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author keshan
 * @date 2022/10/21 - 19:03
 */
@Service
public class HeartrateServicesImpl implements HeartrateServices {
    @Autowired
    HeartrateMapper heartrateMapper;
    @Override
    public int insertBySelectiveHeartrate(Heartrate heartrate) {
        return heartrateMapper.insertSelective(heartrate);
    }

//    @Override
//    public List<Heartrate> getHeartrateListByImeiToday(String imei) {
//        HeartrateExample heartrateExample = new HeartrateExample();
//        HeartrateExample.Criteria criteria = heartrateExample.createCriteria();
//        criteria.andImeiEqualTo(imei);
//        List<Date> dateList = DateUtil.getStartAndEndToday();
//        criteria.andTimeBeginBetween(dateList.get(0),dateList.get(1));
//        List<Heartrate> heartrateList = heartrateMapper.selectByExample(heartrateExample);
//        return heartrateList;
//    }
//
//    @Override
//    public List<HeartrateHide> getHeartrateListHideByImei(String imei) {
//        HeartrateExample heartrateExample = new HeartrateExample();
//        HeartrateExample.Criteria criteria = heartrateExample.createCriteria();
//        criteria.andImeiEqualTo(imei);
//        return heartrateMapper.selectHideByExample(heartrateExample);
//    }

    @Override
    public List<HeartrateHide> getHeartrateListHideByUsernameToday(String username) {
        HeartrateExample heartrateExample = new HeartrateExample();
        HeartrateExample.Criteria criteria = heartrateExample.createCriteria();
        criteria.andUsernameEqualTo(username);
        List<Date> dateList = DateUtil.getStartAndEndToday();
        criteria.andTimeBeginBetween(dateList.get(0),dateList.get(1));
        return heartrateMapper.selectHideByExample(heartrateExample);
    }

    @Override
    public List<HeartrateDayAvg> getHeartrateListEverydayAvgMonth(String username) {
        List<Date> dateList = DateUtil.getStartAndEndTwoMonth();
        System.out.println(dateList.get(0)+"    "+dateList.get(1));
        return heartrateMapper.selectEverydayAvg(dateList.get(0),dateList.get(1),username);
    }
}
